﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using OnlineSoccerManager.Helper;

namespace OnlineSoccerManager.Classes
{
    public class TechnicalSkills
    {
        private Dictionary<string, decimal> technicalSkills = new Dictionary<string, decimal>();
        private Dictionary<string, decimal> technicalChanges = new Dictionary<string, decimal>();
        private List<SkillChange> changeSummary;

        public decimal? Resistance {
            get
            {
                if (this.technicalSkills.ContainsKey("Resistance"))
                    return this.technicalSkills["Resistance"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Resistance"] = value.Value;
            }
        }
        public decimal? Reliability
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Reliability"))
                    return this.technicalSkills["Reliability"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Reliability"] = value.Value;
            }
        }
        public decimal? Kick
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Kick"))
                    return this.technicalSkills["Kick"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Kick"] = value.Value;
            }
        }
        public decimal? Pass
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Pass"))
                    return this.technicalSkills["Pass"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Pass"] = value.Value;
            }
        }
        public decimal? Header
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Header"))
                    return this.technicalSkills["Header"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Header"] = value.Value;
            }
        }
        public decimal? Duel
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Duel"))
                    return this.technicalSkills["Duel"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Duel"] = value.Value;
            }
        }
        public decimal? BallControl
        {
            get
            {
                if (this.technicalSkills.ContainsKey("BallControl"))
                    return this.technicalSkills["BallControl"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["BallControl"] = value.Value;
            }
        }
        public decimal? Velocity
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Velocity"))
                    return this.technicalSkills["Velocity"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Velocity"] = value.Value;
            }
        }
        public decimal? Survey
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Survey"))
                    return this.technicalSkills["Survey"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Survey"] = value.Value;
            }
        }
        public decimal? Covering
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Covering"))
                    return this.technicalSkills["Covering"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Covering"] = value.Value;
            }
        }
        public decimal? Aggressivity
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Aggressivity"))
                    return this.technicalSkills["Aggressivity"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Aggressivity"] = value.Value;
            }
        }
        public decimal? Discipline
        {
            get
            {
                if (this.technicalSkills.ContainsKey("Discipline"))
                    return this.technicalSkills["Discipline"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalSkills["Discipline"] = value.Value;
            }
        }




        public decimal? ResistanceChange
        {
            get {
                if (this.technicalChanges.ContainsKey("ResistanceChange"))
                    return this.technicalChanges["ResistanceChange"];

                return null;
            }
            set {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["ResistanceChange"] = value.Value;
            }
        }
        public decimal? ReliabilityChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("ReliabilityChange"))
                    return this.technicalChanges["ReliabilityChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["ReliabilityChange"] = value.Value;
            }
        }
        public decimal? KickChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("KickChange"))
                    return this.technicalChanges["KickChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["KickChange"] = value.Value;
            }
        }
        public decimal? PassChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("PassChange"))
                    return this.technicalChanges["PassChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["PassChange"] = value.Value;
            }
        }
        public decimal? HeaderChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("HeaderChange"))
                    return this.technicalChanges["HeaderChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["HeaderChange"] = value.Value;
            }
        }
        public decimal? DuelChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("DuelChange"))
                    return this.technicalChanges["DuelChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["DuelChange"] = value.Value;
            }
        }
        public decimal? BallControlChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("BallControlChange"))
                    return this.technicalChanges["BallControlChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["BallControlChange"] = value.Value;
            }
        }
        public decimal? VelocityChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("VelocityChange"))
                    return this.technicalChanges["VelocityChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["VelocityChange"] = value.Value;
            }
        }
        public decimal? SurveyChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("SurveyChange"))
                    return this.technicalChanges["SurveyChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["SurveyChange"] = value.Value;
            }
        }
        public decimal? CoveringChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("CoveringChange"))
                    return this.technicalChanges["CoveringChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["CoveringChange"] = value.Value;
            }
        }
        public decimal? AggressivityChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("AggressivityChange"))
                    return this.technicalChanges["AggressivityChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["AggressivityChange"] = value.Value;
            }
        }
        public decimal? DisciplineChange
        {
            get
            {
                if (this.technicalChanges.ContainsKey("DisciplineChange"))
                    return this.technicalChanges["DisciplineChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.technicalChanges["DisciplineChange"] = value.Value;
            }
        }


        public IEnumerable<SkillChange> ChangeSummary
        {
            get
            {
                if (this.changeSummary != null)
                    return this.changeSummary;

                this.changeSummary = new List<SkillChange>();
                foreach (var entry in this.technicalChanges.Where(e => e.Value != 0))
                    this.changeSummary.Add(new SkillChange() { Icon = (entry.Value > 0 ? this.ChangeUpImage : this.ChangeDownImage), Name = entry.Key, Value = entry.Value });

                return this.changeSummary;
            }
        }
        public ImageSource ChangeUpSource { get { return this.ChangeUpImage.GetImageSource(); } }
        public Bitmap ChangeUpImage { get; set; }
        public ImageSource ChangeDownSource { get { return this.ChangeDownImage.GetImageSource(); } }
        public Bitmap ChangeDownImage { get; set; }
    }
}
